package com.harusoft.interlock;

import java.util.Hashtable;
import java.util.Map;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;

public class PopUpMenu extends Activity implements OnClickListener{

	private String title="";
	private String description="";
	private String videourl="";
	private String imgurl="";
	final static String tag="harusoft";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.interlock4);
		Intent intent=getIntent();
		imgurl=intent.getStringExtra("imgurl");
		title=intent.getStringExtra("title");
		if(title.equals(""))title="Title : None";
		description=intent.getStringExtra("description");
		if(description.equals(""))description="Description : None";
		videourl=intent.getStringExtra("videourl");
		if(videourl.equals(""))videourl="Video Url : None";
		ImageView kakaoImg=(ImageView)findViewById(R.id.interlock4_kakaotalk);
		ImageView storyImg=(ImageView)findViewById(R.id.interlock4_kakaostory);
		ImageView faceImg=(ImageView)findViewById(R.id.interlock4_facebook);
		faceImg.setOnClickListener(this);
		kakaoImg.setOnClickListener(this);
		storyImg.setOnClickListener(this);
	}
	@Override
	public void onClick(View v) {
		switch(v.getId()){
		case R.id.interlock4_kakaotalk:
			KakaoLink kakaoLink = KakaoLink.getLink(getApplicationContext());
			if (!kakaoLink.isAvailableIntent()) return;
			try {
				kakaoLink.openKakaoLink(this, 
						videourl, 
						description, 
						getPackageName(), 
						getPackageManager().getPackageInfo(getPackageName(), 0).versionName, 
						title, 
						"UTF-8");
			} catch (NameNotFoundException e) {
				e.printStackTrace();
			}
			break;
		case R.id.interlock4_kakaostory:
			Map<String, Object> urlInfoAndroid = new Hashtable<String, Object>(1);
			urlInfoAndroid.put("title", title);
			urlInfoAndroid.put("desc", description);
			urlInfoAndroid.put("imageurl", new String[] {imgurl});
			urlInfoAndroid.put("type", "article");
			StoryLink storyLink = StoryLink.getLink(getApplicationContext());
			if (!storyLink.isAvailableIntent()) return;

			try {
				storyLink.openKakaoLink(this, 
						videourl,
						getPackageName(), 
						getPackageManager().getPackageInfo(getPackageName(), 0).versionName, 
						"Youtube",
						"UTF-8", 
						urlInfoAndroid);
			} catch (NameNotFoundException e) {e.printStackTrace();}
			break;
		case R.id.interlock4_facebook : 
			Intent intent = new Intent(this, MainActivity.class);
			intent.putExtra("title", title);
			intent.putExtra("videourl", videourl);
			startActivity(intent);
		}
		finish();
	}
}
